package com.sanji.sjmallmodule.phoneshell;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sanji.sjmallapp.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 订单状态
 * Created by Administrator on 2017/9/16.
 */

public class OrderRecordAdapter extends BaseAdapter {

    private Context mCtx;
    private List<OrderRecordBean> recordList= new ArrayList<>();

    public OrderRecordAdapter(Context context,List<OrderRecordBean> list){
        this.mCtx = context;
        this.recordList = list;
    }

    @Override
    public int getCount() {
        return recordList.size();
    }

    @Override
    public OrderRecordBean getItem(int position) {
        return recordList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RecordHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mCtx).inflate(R.layout.item_adapter_order_record,null);
            holder = new RecordHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (RecordHolder) convertView.getTag();
        }
        OrderRecordBean bean = getItem(position);
        if (bean!=null){
            if (position==0){
                holder.redLeftLayout.setVisibility(View.VISIBLE);
                holder.grayLeftLayout.setVisibility(View.GONE);
                holder.statusTv.setTextColor(mCtx.getResources().getColor(R.color.colorRed));
                holder.statusTv.setTextSize(15);
            }else{
                holder.redLeftLayout.setVisibility(View.GONE);
                holder.grayLeftLayout.setVisibility(View.VISIBLE);
                holder.statusTv.setTextColor(mCtx.getResources().getColor(R.color.color_more3_grey));
                holder.statusTv.setTextSize(14);
            }

            holder.statusTv.setText(bean.getOperation());
            holder.timeTv.setText(bean.getOperationTime());
        }


        return convertView;
    }

    class RecordHolder{
        @BindView(R.id.item_record_red_layout)RelativeLayout redLeftLayout;
        @BindView(R.id.item_record_gray_layout)RelativeLayout grayLeftLayout;
        @BindView(R.id.item_record_status)TextView statusTv;
        @BindView(R.id.item_record_time)TextView timeTv;

        public RecordHolder(View view){
            ButterKnife.bind(this,view);
        }

    }
}
